package airAgent.group5;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class ConfigReader {
	private static final ConfigReader INSTANCE = new ConfigReader();//Singelton don't touch! Alex
//	private String configFileDir = "/home/alex/workspace/absd-group5/bin/airAgent/group5";
//        private String configFileDir = "/home/hector/NetBeansProjects/airline/trunk/src/airAgent/group5";
	/////////////////////////////////////////////////
	//Fields in the config File
	//TODO: Add here more, change the read call, and create getters
	private long timeout = -1; // TODO read from configuration
    private int airlinesCount = -1; // TODO read from configuration
    private int minStay = -1; // TODO read from configuration
    private int maxStay = -1; // TODO read from configuration
    private int simulationDays = -1;
    private int clientsPerDay = -1;
    private int dailyPassengersVariance = -1;
    private float subsidy = -1; // TODO read from configuration
    private float airportTaxes = -1;
    private float fuelCostPerFlight = -1;
    private float helicopterMaintanance = -1;
    private float pilotSalary = -1;
    /////////////////////////////////////////////////
    
    private ConfigReader() { //Singeton don't touch! Alex
    	readConfigFile();
    //	System.out.println("ConfigReader: Created and initialized!");
    	
    }
    
    public static ConfigReader getInstance() {//Call this staicly, instead of a private constructor. Singelton don't touch! alex
        return INSTANCE;
    }
    
    public long getTimeout() {
		return timeout;
	}

	public int getAirlinesCount() {
		return airlinesCount;
	}

	public int getMinStay() {
		return minStay;
	}

	public int getMaxStay() {
		return maxStay;
	}
	
	public int getSimulationDays() {
		return simulationDays;
	}	

	public int getClientsPerDay() {
		return clientsPerDay;
	}		
	
	public int getDailyPassengersVariance() {
		return dailyPassengersVariance;
	}			

	public float getSubsidy() {
		return subsidy;
	}
	
	public float getTaxes() {
		return airportTaxes;
	}
	
	public float getFuel() {
		return fuelCostPerFlight;
	}
	
	public float getHelicopter() {
		return helicopterMaintanance;
	}
	
	public float getPilot() {
		return pilotSalary;
	}
	
	//Add here more getters for new parameters

	private void readConfigFile() {

        try {
            File file = new File("settings.properties");
            Scanner scanner = new Scanner(file);
            while (scanner.hasNextLine()) {
                String configFileLine = scanner.nextLine();
                try{
                    String [] variableValue = configFileLine.split("=");
                    if (variableValue[0].equals("timeout")){
                        timeout = (Long.parseLong(variableValue[1]));
                    }
                    else if (variableValue[0].equals("airlineCount"))
                    {
                        airlinesCount = (Integer.parseInt(variableValue[1]));
                    }
                    else if (variableValue[0].equals("minStay")){
                    	minStay = (Integer.parseInt(variableValue[1]));
                    }
                    else if (variableValue[0].equals("maxStay"))
                    {
                    	maxStay = (Integer.parseInt(variableValue[1]));
                    }
                    else if(variableValue[0].equals("simulationDays")){
                    	simulationDays = (Integer.parseInt(variableValue[1]));
                    }          
                    else if(variableValue[0].equals("clientsPerDay")){
                    	clientsPerDay = (Integer.parseInt(variableValue[1]));
                    }                        
                    else if(variableValue[0].equals("dailyPassengersVariance")){
                    	dailyPassengersVariance = (Integer.parseInt(variableValue[1]));
                    }
                    else if(variableValue[0].equals("subsidy")){
                    	subsidy = (Float.parseFloat(variableValue[1]));
                    }
                    else if(variableValue[0].equals("airportTaxes")){
                    	airportTaxes = (Float.parseFloat(variableValue[1]));
                    }
                    else if(variableValue[0].equals("fuelCostPerFlight")){
                    	fuelCostPerFlight = (Float.parseFloat(variableValue[1]));
                    }
                    else if(variableValue[0].equals("helicopterMaintanance")){
                    	helicopterMaintanance = (Float.parseFloat(variableValue[1]));
                    }
                    else if(variableValue[0].equals("pilotSalary")){
                    	pilotSalary = (Float.parseFloat(variableValue[1]));
                    }
                    
                    // Add here more else if for new parameters
                }catch(Exception e)
                {
                    System.err.println("ClientGeneraor: Cannot parse line in config file: "+configFileLine);
                    e.printStackTrace();
                }

            }
            scanner.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
